package com.whu.config;


import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
@Slf4j
public class ThreadPoolConfig  {
    /*
    * 操作系统可用处理器数量
    */
    public static final int availableProcessors = Runtime.getRuntime().availableProcessors();

    @Bean("pictureServiceExecutor")
    public Executor pictureServiceExecutor(){
        log.info("线程池配置开始");
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(availableProcessors);
        executor.setMaxPoolSize(availableProcessors*2);
        executor.setQueueCapacity(200);
        executor.setKeepAliveSeconds(60);
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setThreadNamePrefix("pictureServiceExecutor--");
        log.info("线程池配置完毕");
        return executor;
    }
}
